﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MrDev.Graphics;
using MrDev.Physics;

namespace MrDev.GameObjects
{
    class Bullet : GameObject
    {
        private Animation animation;

        public Bullet(Level level, Vector2 position) : base(level)
        {
            Parameters = PhysicsParameters.CreateBulletParameters();
            SetColor(Color.White);

            LoadContent();
            Reset(position);
        }

        public void LoadContent()
        {
            // Load animated textures.
            animation = new Animation(Level.Content.Load<Texture2D>("Sprites/Bullets/BulletDisk"), 0.1f, true);
        }

        public override void Update(GameTime gameTime)
        {
            Level.Physics.ApplyPhysics(this, gameTime);
            bool objectCollided = Level.Physics.HandleCollisions(this);
            if (objectCollided)
            {
                IsAlive = false;
            }

        }

        public void Reset(Vector2 position)
        {
            Level.Physics.SetObjectPosition(this, position);
            PlayAnimation(animation);
        }

    }
}
